﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Data;
namespace Text1
{
    class BattleHandler : IHandler
    {
        public void Register(Dictionary<Protocal, Action<SockedClient, ByteBuffer>> handlers)
        {
            handlers.Add(Protocal.PlayerMove_CMD,PlayerMove);
            handlers.Add(Protocal.PlayerFire_CMD, PlayerFire);
            handlers.Add(Protocal.PlayerDead_CMD, PlayerDead);
            handlers.Add(Protocal.PlayerDamage_CMD, PlayerDamage);
        }
        //玩家受伤
        private void PlayerDamage(SockedClient client, ByteBuffer buffer)
        {
            ReqHit hit = ProtoHelper.Deserialize<ReqHit>(buffer.ReadBytes());

            Account hurt = ActorManager.Instance.GetActor(hit.hurtname);
            hurt.hp--;
            if (hurt.hp<=0)
            {
                hit.hp = 0;
                GameSever.Instance.SendAll(Protocal.PlayerDead_CMD,hit);
            }
            else
            {
                hit.hp = hurt.hp;
                GameSever.Instance.SendAll(Protocal.PlayerDamage_CMD, hit);
            }
        }
        //玩家移动   
        private void PlayerMove(SockedClient client, ByteBuffer buffer)
        {
              ReqPosition move = ProtoHelper.Deserialize<ReqPosition>(buffer.ReadBytes());
           GameSever.Instance.SendOther(client, Protocal.PlayerMove_CMD, move);
        }
        //玩家发射子弹
        private void PlayerFire(SockedClient client, ByteBuffer buffer)
        {
            ReqPosition move = ProtoHelper.Deserialize<ReqPosition>(buffer.ReadBytes());
            GameSever.Instance.SendOther(client, Protocal.PlayerFire_CMD, move);
        }
        //玩家死亡
        private void PlayerDead(SockedClient client, ByteBuffer buffer)
        {
            
        }
    }
}
